package weaver.interfaces.jhthome.duss.action;

import com.weaver.general.BaseBean;
import com.weaver.general.Util;
import weaver.conn.RecordSet;
import weaver.hrm.resource.ResourceComInfo;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

public class WeaCfWlxjdAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        writeLog(">>>>>WeaCfWlxjdAction>>>>>requestid=" + requestid);
        writeLog(">>>>>WeaCfWlxjdAction>>>>>tablename=" + tablename);
        JhthomeUtil jhthomeUtil = new JhthomeUtil();
        try {
            rs.execute("select * from " + tablename + " where requestid=" + requestid);
            rs.next();
            String mainid = Util.null2String(rs.getString("id"));
            int count = 0;
            rs.execute("select * from " + tablename + "_dt1 where mainid=" + mainid);
            int counts = rs.getCounts();
            while (rs.next()) {
                String sbr = Util.null2String(rs.getString("sbr"));
                String[] arr = sbr.split(",");
                for (String ryid : arr) {
                    Map<String, Object> requestDt1Map = new HashMap<String, Object>();
                    requestDt1Map.put("mainid", mainid);
                    requestDt1Map.put("bh", Util.null2String(rs.getString("bh")));
                    requestDt1Map.put("wlmcxxgg", Util.null2String(rs.getString("wlmcxxgg")));
                    requestDt1Map.put("bcsm", Util.null2String(rs.getString("bcsm")));
                    requestDt1Map.put("sliang", Util.null2String(rs.getString("sliang")));
                    requestDt1Map.put("dwmm", Util.null2String(rs.getString("dwmm")));
                    requestDt1Map.put("djjmf", Util.null2String(rs.getString("djjmf")));
                    requestDt1Map.put("pcbz", Util.null2String(rs.getString("pcbz")));
                    requestDt1Map.put("jgydpl", Util.null2String(rs.getString("jgydpl")));
                    requestDt1Map.put("sfecjg", Util.null2String(rs.getString("sfecjg")));
                    requestDt1Map.put("yxq", Util.null2String(rs.getString("yxq")));
                    requestDt1Map.put("zzcp", Util.null2String(rs.getString("zzcp")));
                    requestDt1Map.put("kh", Util.null2String(rs.getString("kh")));
                    requestDt1Map.put("sl", Util.null2String(rs.getString("sl")));
                    requestDt1Map.put("ylzssm", Util.null2String(rs.getString("ylzssm")));
                    requestDt1Map.put("qmqq", Util.null2String(rs.getString("qmqq")));
                    requestDt1Map.put("ssl", Util.null2String(rs.getString("ssl")));
                    requestDt1Map.put("bcsx", Util.null2String(rs.getString("bcsx")));
                    requestDt1Map.put("fjsc", Util.null2String(rs.getString("fjsc")));
                    requestDt1Map.put("bjr", ryid);
                    requestDt1Map.put("sbr", Util.null2String(rs.getString("sbr")));
                    requestDt1Map.put("sbje", Util.null2String(rs.getString("sbje")));
                    jhthomeUtil.updateDetailData(tablename + "_dt2", requestDt1Map);
                }
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("Action Exception!");
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}
